//
//  THJDataVC.m
//  THJXHW
//
//  Created by 河南德艺 on 17/3/7.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJDataVC.h"
#import "THJDataView.h"
#import "THJCompanyVC.h"
#import "THJProductDetailVC.h"
#import "THJClassViewController.h"
#import "THJSearchVC.h"
#import "THJAllClassVC.h"
#import "THJStorePurchaseVC.h"
#import "THJCompanyListVC.h"
#import "THJFlashNewsVC.h"
#import "LMHWaterFallController.h"
#import "THJPurchaseVC.h"
#import "THJFabuSupplyVC.h"
@interface THJDataVC ()<THJDataViewDelegate>
{
    UIButton * btn;
}
@property (weak, nonatomic) IBOutlet UIView *searchView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * topSpace;
@property (weak, nonatomic) IBOutlet UIView * headView;

@end

@implementation THJDataVC
-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
//    [[LBTabBarController sharedTabBarC].fabuView removeFromSuperview];
//    [self.navigationController.navigationBar setHidden:NO];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar setHidden:YES];
    [self.tabBarController.tabBar setHidden:NO];
    [self setStateBarColor:COLOR(83, 84, 85, 1)];
     
}
-(void)viewDidLoad{
    [super viewDidLoad];
    CGFloat space;
    if(KIsiPhoneX){
        self.topSpace.constant = 20;
        space = 85;
    }else{
        self.topSpace.constant = 0;
        space = 65;
    }
    THJDataView * view = [[THJDataView alloc] initWithFrame:CGRectMake(0, space, ScreenWidth, ScreenHeight)];
    view.delegate = self;
    //搜搜框添加手势
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(searchTap)];
    [self.searchView addGestureRecognizer:tap];
    [self.view addSubview:view];
    
    [self setFabuBtn];
}
-(void)setFabuBtn{
    btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(ScreenWidth - 100, ScreenHeight - 120, 35, 35);
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(fabuBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [btn setBackgroundImage:kGetImage(@"加号") forState:UIControlStateNormal];
}
-(void)fabuBtnAction{
    NSLog(@"发布供应");
    [self.view addSubview:self.fabuView];
    [self performSelector:@selector(fabuViewDismiss) withObject:nil afterDelay:3];
}
-(void)fabuViewDismiss{
    [self.fabuView removeFromSuperview];
}
//搜索框点击
-(void)searchTap{
    NSLog(@"点击搜索框");
    [self.navigationController pushViewController:[THJSearchVC new] animated:YES];
}
#pragma mark --分类按钮点击--
-(void)BtnclickWithIndex:(NSInteger)index clickType:(NSString *)type Dic:(NSDictionary *)dic{
    if([type isEqual:@"btnsClick"]){
        NSLog(@"btnclick-%@",dic);
        if(index == 8){
            //全部商品
            THJAllClassVC * vc = [THJAllClassVC new];
            vc.midType = @"6";
            vc.from = @"商城";
            [self.navigationController pushViewController:vc animated:YES];
        }else if(index == 9){
            [self.navigationController pushViewController:[THJStorePurchaseVC new] animated:YES];
        }else{
            THJClassViewController * vc = [THJClassViewController new];
            vc.productCatid = dic[@"id"];
            [self.navigationController pushViewController:vc animated:YES];
        }
    }else if([type isEqual:@"cellClick"]){
        
        THJProductDetailVC * vc =   [THJProductDetailVC new];
        vc.itemid  = dic[@"itemid"];
        [self.navigationController pushViewController:vc animated:YES];
    }else{
//        [self.navigationController pushViewController:[THJCompanyVC new] animated:YES];
    }
}
#pragma mark ---更多公司---
-(void)getMoreCompany{
    NSLog(@"更多公司");
//     [self.navigationController pushViewController:[THJFlashNewsVC new] animated:YES];
    [self.navigationController pushViewController:[THJCompanyListVC new] animated:YES];
}
#pragma mark --点击实力商家--
-(void)companyClickWithInfoDic:(NSDictionary *)dic{
    NSLog(@"dic-UUU-%@",dic);
    THJCompanyVC * vc = [THJCompanyVC new];
    vc.cid = dic[@"id"];
//    LMHWaterFallController * vc = [LMHWaterFallController new];
    [self.navigationController pushViewController:vc animated:YES];
}
//点击发布按钮 弹出的view
-(UIView*)fabuView{
    if(!_fabuView){
        _fabuView = [[UIView alloc]init];
        _fabuView.frame = CGRectMake(ScreenWidth - 100 - 22.5, ScreenHeight - 120 - 100, 80, 100);
        _fabuView.backgroundColor = SingleColor(clearColor);
        _fabuView.layer.cornerRadius = 5;
        NSArray * titleArr = @[@"供应",@"求购",@"供应"];
        UIImageView * imgV = [[UIImageView alloc] init];
        imgV.frame = CGRectMake(25, 71, 30, 30);
        imgV.image = kGetImage(@"fabujt");
        [_fabuView addSubview:imgV];
        
        UIView * lineview = [[UIView alloc] init];
        lineview.frame = CGRectMake(0,40, 80, 1);
        lineview.backgroundColor = SingleColor(lightGrayColor);
        [_fabuView addSubview:lineview];
        
        for (NSInteger i = 0; i<2; i++) {
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeSystem];
            btn.backgroundColor = COLOR(57, 61, 63, 1);
            btn.titleLabel.font = [UIFont systemFontOfSize:16];
            [btn setTitleColor:SingleColor(lightGrayColor) forState:UIControlStateNormal];
            [btn setTitle:titleArr[i] forState:UIControlStateNormal];
            btn.frame = CGRectMake(0, i*(40+1), 80, 40);
            [btn addTarget:self action:@selector(fabu:) forControlEvents:UIControlEventTouchUpInside];
            btn.tag = i+100;
            [_fabuView addSubview:btn];
        }
    }
    return _fabuView;
}
-(void)fabu:(UIButton*)btn{
    if(![THJTools IsLogIn]){
        [self HUDShowMsg:@"请先登录" AfterDelayDimiss:1];
        return;
    }
    if(btn.tag == 100){
        THJPurchaseVC * vc = [THJPurchaseVC new];
        vc.PTitle = @"发布供应";
        UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:vc];
        [self presentViewController:nav animated:YES completion:^{
            
        }];
    }else{
        THJFabuSupplyVC * vc = [THJFabuSupplyVC new];
        vc.STitle = @"发布求购";
        UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:vc];
        [self presentViewController:nav animated:YES completion:^{
        }];
    }
}
@end
